﻿using MediatR;
using Traceability.APP.Application.Command.Deepprocessings;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Deepprocessings
{
    public class GetMachiningEnterpriseCommandHandLer : IRequestHandler<GetMachiningEnterpriseCommand, APIResult<List<MachiningEnterprise>>>
    {
        private readonly IBaseRepostiy<MachiningEnterprise> _machiningEnterprise;

        public GetMachiningEnterpriseCommandHandLer(IBaseRepostiy<MachiningEnterprise> machiningEnterprise)
        {
            _machiningEnterprise = machiningEnterprise;

        }

        public async Task<APIResult<List<MachiningEnterprise>>> Handle(GetMachiningEnterpriseCommand request, CancellationToken cancellationToken)
        {
            // 获取所有养殖信息
            var list = _machiningEnterprise.GetAll().Where(x => !x.IsDeleted);

            // 根据批次筛选
            list = list.Where(x => x.Batch == request.Batch);

            return new APIResult<List<MachiningEnterprise>>
            {
                Code = ResultCode.Ok,
                Data = list.ToList(),
                Message = "获取成功"
            };
        }
    }
}
